package model;

import java.io.Serializable;

import javax.persistence.*;

import dtos.MeanOfTransportationDTO;
import dtos.TripDTO;

import java.util.LinkedList;
import java.util.List;


/**
 * The persistent class for the trip database table.
 * 
 */
@Entity
@NamedQuery(name="Trip.findAll", query="SELECT t FROM Trip t")
public class Trip implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	private int tripID;

	private String arrivalPlace;

	private String departurePlace;

	//bi-directional many-to-one association to MeanOfTransportation
	@OneToMany(mappedBy="trip", cascade={CascadeType.PERSIST})
	private List<MeanOfTransportation> meanOfTransportations;

	public Trip() {
	}
	
	public Trip(TripDTO trip){
		this.arrivalPlace = trip.getArrivalPlace();
		this.departurePlace = trip.getDeparturePlace();
		this.tripID = trip.getTripID();
	}
	
	public TripDTO getDTO(){
		TripDTO t = new TripDTO();
		t.setArrivalPlace(this.arrivalPlace);
		t.setDeparturePlace(this.departurePlace);
		//t.setMeanOfTransportations(this.getMeanOfTransportationsDTO());
		t.setTripID(this.tripID);
		return t;
	}

	public int getTripID() {
		return this.tripID;
	}

	public void setTripID(int tripID) {
		this.tripID = tripID;
	}

	public String getArrivalPlace() {
		return this.arrivalPlace;
	}

	public void setArrivalPlace(String arrivalPlace) {
		this.arrivalPlace = arrivalPlace;
	}

	public String getDeparturePlace() {
		return this.departurePlace;
	}

	public void setDeparturePlace(String departurePlace) {
		this.departurePlace = departurePlace;
	}

	/*public List<MeanOfTransportation> getMeanOfTransportations() {
		return this.meanOfTransportations;
	}
	
	public List<MeanOfTransportationDTO> getMeanOfTransportationsDTO() {
		List<MeanOfTransportationDTO> res = new LinkedList<MeanOfTransportationDTO>();
		for (MeanOfTransportation t : this.meanOfTransportations){
			res.add(t.getDTO());
		}
		return res;
		
	}

	public void setMeanOfTransportations(List<MeanOfTransportation> meanOfTransportations) {
		this.meanOfTransportations = meanOfTransportations;
	}

	public MeanOfTransportation addMeanOfTransportation(MeanOfTransportation meanOfTransportation) {
		getMeanOfTransportations().add(meanOfTransportation);
		meanOfTransportation.setTrip(this);

		return meanOfTransportation;
	}

	public MeanOfTransportation removeMeanOfTransportation(MeanOfTransportation meanOfTransportation) {
		getMeanOfTransportations().remove(meanOfTransportation);
		meanOfTransportation.setTrip(null);

		return meanOfTransportation;
	}*/

}